var Website = function(obj)
{
	this.implemented_object;
	
	this.multiple = undefined;
	this.domexp_container = undefined;
	this.rexp_item = undefined;
	this.rexp_values = undefined;
	this.name = undefined;
	
	this.renderItem = function() { return this.implemented_object.renderItem(); }
	this.getUrl = function() { return this.implemented_object.getUrl(); }
	this.getPages = function() { return this.implemented_object.getPages(); }
	
	this.getItems = function(doc)
	{
		var exp = new DOMExp(this.domexp_container);
		
		var elem = exp.exec(this.domexp_container);
		
		
		if (!elem)
		{
			console.log("Element conteneur non trouvé pour le site "+this.name+" ! Document renvoyé: ");
			console.log(doc);
			return [];
		}
		//console.log(elem.innerHTML)
		
		exp = new DOMExp(this.domexp_item);
		var items = exp.exec(elem,DOMExp.MULTIPLE_RESULT);
		
		if (!items)
		{
			console.log("Elements items non trouvés pour le site "+this.name+" ! Element conteneur: ");
			console.log(elem);
			return [];
		}
		
		var exp = this.getExpForItem();
		
		var regexp = new RegExp(this.rexp_item)
		
		var matches = regexp.exec(items[0].innerHTML)
		
		console.log(matches.length)
		console.log(matches[1])
		//console.log(regexp)
		//r = new RegExp(this.rexp_item,"ig")
		//var items = r.exec(html)
		
		//console.log(items);
		
	};
	
	
};

Website.list_implements = {
	multiple: "boolean",
	domexp_container: "string",
	domexp_item: "string",
	renderItem: "function",
	getExpForItem: "function",
	getUrl: "function",
	getPages: "function",
	name: "string"
}


Website.implement = function(obj)
{
	var err = false;
	for (var i  in Website.list_implements)
	{
		var attr_name = i;
		var value = obj[attr_name]
		var type = Website.list_implements[i]
		
		if (typeof(type) != "string")
			continue;
			
		if (typeof(value) != type)
		{
			err = true
			if (typeof(value) == "undefined")
				console.error(attr_name+" must be defined and be type of: "+type)
			else
				console.error(attr_name+" must be of type: "+type)
		}
	}
	if (err)
		console.error("Cannot implements Website on "+obj+" !")
	else
	{
		var w = new Website(obj);
		for (var i  in Website.list_implements)
		{
			var attr_name = i;
			var value = obj[attr_name]
			var type = Website.list_implements[i]
			
			if (typeof(type) != "string")
				continue;
			
			if (type != "function")
				w[attr_name] = obj[attr_name]
		}
		w.implemented_object = obj;
		Website.websites.push(w);
		return w;
	}
};

Website.websites = [];
